﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using YakShaver.Contract;
namespace YakShaver
{
	public sealed partial class WorkItemEntryWorkflow: SequentialWorkflowActivity
	{

        //private IWorkItemDataContract _workItemDataContract;
        private bool _endWhileLoop = false; //ghetto way of doing this... but just for testing hopefully.

        public bool EndWhileLoop
        {
            get { return _endWhileLoop; }
            set { _endWhileLoop = value; }
        }
        private bool _workItemIntervenedUponWithLotsOfCrying = false;
        private IWorkItemDataContract _workItemDataContract;
        private TimeSpan _notificationCycleDelay = new TimeSpan(0,0,60);
        private bool _workItemNeedsIntervention = true;

        public bool WorkItemNeedsIntervention
        {
            get { return _workItemNeedsIntervention; }
            set { _workItemNeedsIntervention = value; }
        }

        public IWorkItemDataContract WorkItemDataContract
        {
            get { return _workItemDataContract; }
            set { _workItemDataContract = value; }
        }

        public TimeSpan NotificationCycleDelay
        {
            get { return _notificationCycleDelay; }
            set { _notificationCycleDelay = value; }
        }
        public int NotifyCount
        {
            get { return (int)base.GetValue(NotifyCountProperty); }
            set { base.SetValue(NotifyCountProperty,value); }
        }

        public bool WorkItemIntervened
        {
            get { return _workItemIntervenedUponWithLotsOfCrying; }
            set { _workItemIntervenedUponWithLotsOfCrying = value; }
        }

        private YakShaverWorkItem _workItem;

        public YakShaverWorkItem WorkItem
        {
            get { return _workItem; }
            set { _workItem = value; }
        }

		public WorkItemEntryWorkflow()
		{
			InitializeComponent();
		}

        public static DependencyProperty NotifyCountProperty = DependencyProperty.Register("NotifyCount", typeof(int), typeof(WorkItemEntryWorkflow));

        public static DependencyProperty callProviderNotifyForIntervention_MethodInvoking1Event = DependencyProperty.Register("callProviderNotifyForIntervention_MethodInvoking1", typeof(System.EventHandler), typeof(YakShaver.WorkItemEntryWorkflow));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute("Handlers")]
        public event EventHandler callProviderNotifyForIntervention_MethodInvoking1
        {
            add
            {
                base.AddHandler(callProviderNotifyForIntervention_MethodInvoking1Event, value);
            }
            remove
            {
                base.RemoveHandler(callProviderNotifyForIntervention_MethodInvoking1Event, value);
            }
        }

        public static DependencyProperty callProviderNotifyForIntervention__ReturnValue_1Property = DependencyProperty.Register("callProviderNotifyForIntervention__ReturnValue_1", typeof(System.Boolean), typeof(YakShaver.WorkItemEntryWorkflow));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute("Parameters")]
        public Boolean callProviderNotifyForIntervention__ReturnValue_1
        {
            get
            {
                return ((bool)(base.GetValue(YakShaver.WorkItemEntryWorkflow.callProviderNotifyForIntervention__ReturnValue_1Property)));
            }
            set
            {
                base.SetValue(YakShaver.WorkItemEntryWorkflow.callProviderNotifyForIntervention__ReturnValue_1Property, value);
            }
        }


        public static DependencyProperty WorkItemInterventionNeededEvent = DependencyProperty.Register("WorkItemInterventionNeeded", typeof(System.EventHandler<System.Workflow.Activities.ConditionalEventArgs>), typeof(YakShaver.WorkItemEntryWorkflow));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute("Handlers")]
        public event EventHandler<ConditionalEventArgs> WorkItemInterventionNeeded
        {
            add
            {
                base.AddHandler(WorkItemInterventionNeededEvent, value);
            }
            remove
            {
                base.RemoveHandler(WorkItemInterventionNeededEvent, value);
            }
        }

        private void callNotifyProviderForIntervention_MethodInvoking(object sender, EventArgs e)
        {

            NotifyCount++;
            TrackData("NotifyCount", NotifyCount);
            TrackData("WorkItem", WorkItem);
        }

        private void handleWorkItemIntervened(object sender, ExternalDataEventArgs e)
        {
            this.WorkItemIntervened = true;

            this.WorkItemDataContract = this.WorkItemModifiedEventArgs.ModifiedWorkItem;
            YakShaver.Contract.WorkItemModifiedEventArgs args = (YakShaver.Contract.WorkItemModifiedEventArgs)e;
        }
      
       

        public static DependencyProperty WorkItemModifiedEventArgsProperty = DependencyProperty.Register("WorkItemModifiedEventArgs", typeof(YakShaver.Contract.WorkItemModifiedEventArgs), typeof(YakShaver.WorkItemEntryWorkflow));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute("Parameters")]
        public WorkItemModifiedEventArgs WorkItemModifiedEventArgs
        {
            get
            {
                return ((YakShaver.Contract.WorkItemModifiedEventArgs)(base.GetValue(YakShaver.WorkItemEntryWorkflow.WorkItemModifiedEventArgsProperty)));
            }
            set
            {
                base.SetValue(YakShaver.WorkItemEntryWorkflow.WorkItemModifiedEventArgsProperty, value);
            }
        }

        private void UpdateWorkItemIntervened_ExecuteCode(object sender, EventArgs e)
        {
            this.WorkItemIntervened = true;

            this.WorkItemDataContract = this.WorkItemModifiedEventArgs.ModifiedWorkItem;
            //YakShaver.Contract.WorkItemModifiedEventArgs args = (YakShaver.Contract.WorkItemModifiedEventArgs)e;
        }

        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {
            Console.WriteLine("made it to the end");
        }

      
	}

}
